﻿@{
    ViewBag.Title = "Update";
    Layout = "~/Views/Shared/_Admin_Layout.cshtml";
    ViewBag.Controller = "questions";
    ViewBag.Cate = "Câu hỏi";
    ViewBag.Module = "Add New Questions";
}

<script type="text/javascript">
    $(function () {
        $('#_btn_add').live('click', function () {
            var name = $("#_username").val();
            var address = $("#geocomplete").val();
            var description = $("#_description").val();
            //Check Name
            if (name == '') {
                show_errors("Chưa nhập tên địa danh.");
                return false;
            }

            //Check Address
            if (address == '') {
                show_errors("Chưa nhập địa chỉ.");
                return false;
            }

            UpdateItem("@ViewBag.Controller");

            return false;
        });
    });
</script>

<!--Tabs-->
<div class="tabs">
    <span class="item"><a href="/admin" title="">Bảng điều khiển</a></span>
    <span class="icon-arrow">&gt;</span>
    <span class="item"><a href="/admin/@ViewBag.Controller" title="">@ViewBag.Cate</a></span>
    <span class="icon-arrow">&gt;</span>
    <span class="item">Cập nhật</span>
</div>
<!--End Tabs-->

<!--Container-->
<div class="container">
	<form class="table-content" id="_PostData" method="post">
        <div class="list-btn">
            <a href="/admin/@ViewBag.Controller" class="btn btn-primary" title="Danh sách">Danh sách</a>
            @if (ViewBag.View == null)
            { 
                <input type="submit" class="btn btn-success" id="_btn_add" value="Lưu" />
            }
            else
            {
                <input type="submit" class="btn btn-warning" id="_btn_add" value="Cập nhật" />
            }
        </div>
        <div class="clearAll"></div>
        <div class="notice"><span class="close-notice icon-remove"></span></div>
		<div class="title"><span class="icon-user"></span>@ViewBag.Module</div>
		<div class="error"></div>
		<div class="box-field">
            <input type="hidden" name="id" id="_id" value="@if (ViewBag.View != null)
                                                           {@ViewBag.View.id}"/>
            <table class="altrowstable" id="alternatecolor">
                <tr>
                    <th>Tên Field</th><th>Input Field</th>
                </tr>
                <tr>
                    <td>Câu hỏi</td>
                    <td><input type="text" name="contents" id="_contents" value="@if (ViewBag.View != null)
                                                                                 { @ViewBag.View.contents }" style="min-width:500px" /></td>
                </tr>
                <tr>
                    <td>Địa danh</td>
                    <td>
                        <select name="locationid" id="_locationid">
                            @{
                                foreach (var item in ViewBag.Locations)    
                                {
                                    <option value="@item.id" @if (ViewBag.View != null && @ViewBag.View.pid == @item.id) { Write("selected"); }>@item.name</option>
                                }
                            }
                        </select>
                    </td>
                </tr>
                    @if (ViewBag.View != null)
                    {
                        ViewBag.AS = ViewBag.View.answers.Split(new string[] { "<%%>" }, 4, StringSplitOptions.None);
                    }
                <tr>
                    <td>Câu A</td>
                    @if (ViewBag.AS != null && ViewBag.AS.Length != 0)
                    {
                        ViewBag.A = ViewBag.AS[0].Split(new string[] { "<@@>" }, 4, StringSplitOptions.None);   
                    }
                    <td><input type="text" name="items" id="_ans_a" value="@if (ViewBag.AS != null && ViewBag.A.Length != 0)
                                                                           {@ViewBag.A[0]}" placeholder="A" /></td>
                </tr>
                <tr>
                    <td>Câu B</td>
                    @if (ViewBag.AS != null && ViewBag.AS.Length != 0)
                    {
                        ViewBag.A = ViewBag.AS[1].Split(new string[] { "<@@>" }, 4, StringSplitOptions.None);   
                    }
                    <td><input type="text" name="items" id="_ans_b" value="@if(ViewBag.AS != null && ViewBag.A.Length != 0){@ViewBag.A[0]}" placeholder="B" /></td>
                </tr>
                <tr>
                    <td>Câu C</td>
                    @if (ViewBag.AS != null && ViewBag.AS.Length != 0)
                    {
                        ViewBag.A = ViewBag.AS[2].Split(new string[] { "<@@>" }, 4, StringSplitOptions.None);   
                    }
                    <td><input type="text" name="items" id="_ans_c" value="@if(ViewBag.AS != null && ViewBag.A.Length != 0){@ViewBag.A[0]}" placeholder="C"  /></td>
                </tr>
                <tr>
                    <td>Câu D </td>
                    @if (ViewBag.AS != null && ViewBag.AS.Length != 0)
                    {
                        ViewBag.A = ViewBag.AS[3].Split(new string[] { "<@@>" }, 4, StringSplitOptions.None);   
                    }
                    <td><input type="text" name="items" id="_ans_d" value="@if(ViewBag.AS != null && ViewBag.A.Length != 0){@ViewBag.A[0]}" placeholder="D"  /></td>
                </tr>
                <tr>
                    <td>Câu trả lời đúng</td>
                    <td>
                        <select name="answer">
                            <option value="1">Câu A</option>
                            <option value="2">Câu B</option>
                            <option value="3">Câu C</option>
                            <option value="4">Câu D</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>Trạng thái</td>
                    <td><input type="checkbox" name="status" id="_status" value="1" @if (ViewBag.View != null && ViewBag.View.status == 1) { Write("checked"); } /></td>
                </tr>
            </table>
		</div>
	</form>         
</div>
<!--End Container-->